package com.csst.action;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.csst.bean.Account;
import com.csst.bean.User;
import com.csst.service.AccountService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller
public class AccountEditAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String oldaccpassword;
	private String newaccpassword;
	private String renewaccpassword;
	@Resource
	private AccountService service;
	public String getOldaccpassword() {
		return oldaccpassword;
	}
	public void setOldaccpassword(String oldaccpassword) {
		this.oldaccpassword = oldaccpassword;
	}
	public String getNewaccpassword() {
		return newaccpassword;
	}
	public void setNewaccpassword(String newaccpassword) {
		this.newaccpassword = newaccpassword;
	}
	public String getRenewaccpassword() {
		return renewaccpassword;
	}
	public void setRenewaccpassword(String renewaccpassword) {
		this.renewaccpassword = renewaccpassword;
	}
	@Override
	public String execute() throws Exception {
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session=context.getSession();
		User user=(User) session.get("user");
		if (user.getAccount().getAccpassword().equals(oldaccpassword)) {
			user.getAccount().setAccpassword(newaccpassword);
			Account account=user.getAccount();
			service.updateAccount(account);
			return SUCCESS;
		}
		return "fail";
	}

	
}
